package com.ghn.cocknovel.ui.activity.setting

import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import com.blankj.utilcode.util.ActivityUtils
import com.example.basemodel.base.BaseHeadVMActivity
import com.example.basemodel.base.BaseViewModel
import com.example.basemodel.base.DefaultHeadStyle
import com.ghn.cocknovel.R
import com.ghn.cocknovel.databinding.ActivitySettingBinding
import com.ghn.cocknovel.ext.setIsLogin
import com.ghn.cocknovel.ui.activity.start.StartActivity
import com.kt.NetworkModel.utils.MVUtils

/**
 *@author: Administrator
 *2023/10/9
 *desc:设置
 */
class SettingActivity : BaseHeadVMActivity<BaseViewModel, ActivitySettingBinding, DefaultHeadStyle>() {
    override fun layoutId(): Int = R.layout.activity_setting

    @SuppressLint("SetTextI18n")
    override fun initView(savedInstanceState: Bundle?) {
        mHeadStyle.setLeftImageResource(R.mipmap.ic_back_black)
        mHeadStyle.setTitleColor("设置", getColor(R.color.black))
        mHeadStyle.setTitleBackgroundColor(getColor(R.color.colorBackGround))
        mDatabind.tvVersionName.setText("v" + getAppVersionName())
        mDatabind.btnChangPassWord.setOnClickListener {
            startActivity(Intent(this@SettingActivity, ChangePassWordActivity::class.java))
        }
        mDatabind.settingFeedback.setOnClickListener {
            startActivity(Intent(this, FeedbackActivity::class.java))
        }
        mDatabind.btnLoginOut.setOnClickListener {
            // 直接清除数据
            MVUtils.setIsLogin(false)
            startActivity(Intent(this, StartActivity::class.java))
            ActivityUtils.addActivityLifecycleCallbacks(this, null)
            finish()
        }
    }

    private fun getAppVersionName(): String {
        return try {
            val packageInfo = packageManager.getPackageInfo(packageName, 0)
            packageInfo.versionName
        } catch (e: PackageManager.NameNotFoundException) {
            "Unknown"
        }
    }

    override fun createObserver() {


    }
}